﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace NoteHelper.Sys
{
	public class Sysm000Controller
	{
		private int rowIndex;
		private IBaseView view;
		public Sysm000Controller(IBaseView baseView)
		{
			view = baseView;

			view.Insert += Form_Insert;
			view.Edit += Form_Edit;
			view.Remove += Form_Remove;
			view.Copy += Form_Copy;
			view.Query += Form_Query;
			view.Accept += Form_Accept;
			view.Cancel += Form_Cancel;
			view.Print += Form_Print;
			view.Help += Form_Help;
		}
		private void Form_Insert(object sender, EventArgs e)
		{
			view.RowData = null;
			view.Cmd = FormCommand.Insert;
			view.BeginEdit();
		}
		private void Form_Edit(object sender, EventArgs e)
		{
			BeginEdit(FormCommand.Edit);
		}
		private void Form_Remove(object sender, EventArgs e)
		{
			throw new NotImplementedException();
		}
		private void Form_Copy(object sender, EventArgs e)
		{
			BeginEdit(FormCommand.Insert);
		}
		private void BeginEdit(FormCommand cmd)
		{
			rowIndex = view.GetRowIndex();
			if (rowIndex == -1) return;

			var ht = new Hashtable();
			view.RowData = ht;
			view.Cmd = cmd;
			view.BeginEdit();
		}
		private void Form_Query(object sender, EventArgs e)
		{
			view.RowData = null;
			view.Cmd = FormCommand.Query;
			view.BeginEdit();
		}
		private void Form_Accept(object sender, EventArgs e)
		{
			bool error = false;
			switch (view.Cmd)
			{
				default:
					break;
			}
			if (error) return;
			view.RowData = null;
			view.Cmd = FormCommand.Display;
			view.EndEdit();
		}
		private void Form_Cancel(object sender, EventArgs e)
		{
			view.RowData = null;
			view.Cmd = FormCommand.Display;
			view.EndEdit();
		}
		private void Form_Print(object sender, EventArgs e)
		{
			throw new NotImplementedException();
		}
		private void Form_Help(object sender, EventArgs e)
		{
			throw new NotImplementedException();
		}
	}
}
